package core.hmxchen.log;

/**
 * @program: tongdao-plus
 * @description:
 * @author: hmxchen
 * @create: 2021-09-03 11:30
 **/
public class LogFormatterFactory {

    public static LogFormatter getClassName(String clazzName) {
        try {
            Class<?> clazz = Class.forName(clazzName);
            if (clazz.newInstance() instanceof LogFormatter) {
                return (LogFormatter) clazz.newInstance();
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        throw new IllegalArgumentException("格式解析类继承错误");
    }
    public static RequestLogFormatter getRequestByName(String clazzName) {
        try {
            Class<?> clazz = Class.forName(clazzName);
            if (clazz.newInstance() instanceof LogFormatter) {
                return (RequestLogFormatter) clazz.newInstance();
            }
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) {
            e.printStackTrace();
        }
        throw new IllegalArgumentException("格式解析类继承错误");
    }
}
